#include <linux/sched.h>
#include <linux/pid.h>
#include <linux/module.h>

static int __init pidtest_initfunc(void)
{
  printk("调用pidtes_initfunc(...)函数 \n");
  // 1: find_get_fid(....);
  struct pid* kernelpid = find_get_pid(current->pid);
  printk("打印进程描述符 count 的值: %d\n", kernelpid->count);
  printk("打印进程描述符 level 的值: %d\n", kernelpid->level);
  printk("打印进程描述符 numbers 的值: %d\n", kernelpid->numbers[kernelpid->level].nr);

// 2: pid_nr()
	int nr = pid_nr(kernelpid);
   	printk("打印进程描述符的全局进程编号为： %d\n",nr);	
   	printk("打印进程描述符的当前线程组编号为： %d\n", current->tgid);

// 3 pid_task();
	struct task_struct *ttask = pid_task(kernelpid, PIDTYPE_PID);
	printk("打印任务当前状态为: %ld\n", ttask->state);
	printk("打印任务当前进程号为: %d\n", ttask->pid);

// 4: __task_pid_nr_ns(...)
	pid_t rest = __task_pid_nr_ns(ttask, PIDTYPE_PID, kernelpid->numbers[kernelpid->level].ns);
	printk("调用__task_pid_nr_ns(....)函数，输出结果为：%d\n", rest);

  printk("退出 pidtest_initfunc(...)函数\n");
		return 0;
}

static void __exit pidtest_exitfunc(void)
{
		printk("正常退出Linux内核... \n");
}


MODULE_LICENSE("GPL");

module_init(pidtest_initfunc);
module_exit(pidtest_exitfunc);
